Skip to content

fix(monitor): cap Span.Progress so a Running zero-total child cannot push count past total#1249

Open
SAY-5 wants to merge 1 commit intogorse-io:masterfrom
SAY-5:fix/progress-zero-total-running-overflow-1241
Open

fix(monitor): cap Span.Progress so a Running zero-total child cannot push count past total#1249
SAY-5 wants to merge 1 commit intogorse-io:masterfrom
SAY-5:fix/progress-zero-total-running-overflow-1241

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 21, 2026

What

Fixes #1241.

Span.Progress was treating every zero-total child as fully complete by adding childTotal to parentCount. Combined with the parent's own count*childTotal term, this produced parentCount > parentTotal whenever the parent had already finished its own work and a Running zero-total child was still registered. The dashboard then rendered the task at >100%.

Repro (from the issue)

Parent total=2, count=2, one Running zero-total child:

step parentCount parentTotal
childTotal = max(0) → fallback 1
seed: s.count * childTotal 2 2
zero-total child branch (old) 3 2
Progress{Count: 3, Total: 2} (150%)

Fix

A Running zero-total child has no measurable progress yet. Once it completes, it is filtered out of the children loop entirely (the loop only includes StatusRunning) and the parent's own count covers it through the s.count * childTotal term. So the right thing to do is contribute 0 for any zero-total child that is still in the loop, rather than treating its empty work as a finished branch.

Tests

  • Updated the existing divide by zero / child with zero total / all children with zero total cases to reflect the corrected accounting (Running zero-total contributes 0, not childTotal).
  • Added zero-total running child does not exceed parent total as the focused regression for the report. On master it fails with Count (3) must not exceed Total (2); with the fix it passes.

Verification

Locally on macOS, go 1.26.2:

  • gofmt -s -l common/monitor/: clean
  • go vet ./common/monitor/...: clean
  • go test -race -count=1 ./common/monitor/...: pass

Closes #1241

…st parentTotal

Span.Progress treated every zero-total child as fully complete by
adding childTotal to parentCount. Combined with the parent contributing
its own count*childTotal, this produced parentCount > parentTotal
whenever the parent had already finished its own work and a Running
zero-total child was still registered. The dashboard then rendered the
task at >100%.

A Running zero-total child has no measurable progress yet; once it
completes, it is filtered out of the children loop entirely and the
parent's own count covers it via the s.count * childTotal term. So
the right thing to do is contribute 0 for any zero-total child still
in the loop, rather than treating its empty work as a finished branch.

Update the existing 'divide by zero' / 'child with zero total' /
'all children with zero total' tests to reflect the corrected
accounting (Running zero-total contributes 0, not childTotal), and
add a focused regression for the parent-finished-with-running-child
scenario from the report. The new assertion fails on master with
'Count (3) must not exceed Total (2)'.

Closes gorse-io#1241

Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Span.Progress returns Count > Total when a running child has Total == 0 (follow-up to #1208)

1 participant